home *** CD-ROM | disk | FTP | other *** search
- /**********************************************/
- /* English Clock 7.0 */
- /* ================== */
- /* */
- /* Coding: Ben Matthew */
- /* Date: (C) 1995 */
- /* */
- /* based on an UNIX program of similar name */
- /* */
- /* Compiled using SAS/C by the SAS */
- /* Institute */
- /* */
- /**********************************************/
-
- static char *vers="$VER: English Clock 7.0 © Ben Matthew (19.05.96)";
-
- #include "globals.h"
-
- /* #define DEBUG_CODE */
-
- int timerdev;
- struct MsgPort *TimerPort=NULL;
- BOOL cxsucc, rexxsucc;
-
- extern char *__procname="EngClock_7.0";
- extern long __stack=5000;
-
- /********* Main loop *************/
-
- short main(int argc, char *argv[]) {
- /* Stuff for timer */
- int TimerSig;
- struct Message *mess=NULL;
- long sig, winsig, totalsig;
- long cxsig, id, hot1sig, hot2sig, rexxsig;
- /* Stuff for IDCMP */
- ULONG class;
- USHORT code;
- /* Misc */
- BOOL flag1=FALSE;
- int mem1=70, mem2=70;
- char newline[500];
-
- openall(); /* Opens all the libraries required */
-
- /* Get a lock on the screen we want to open the win on.. */
- /* This lock will be held until we close to avoid nasty crashing ! */
-
- readprefs();
- process_args(argc, argv);
-
- pubscreen=LockPubScreen(prefs.pub);
- if(!pubscreen) {
- msg("Cannot lock specified public screen!");
- pubscreen=LockPubScreen(NULL);
- if(!pubscreen) {
- msg("Cannot lock Workbench!");
- closeall();
- return(0);
- }
- }
-
- getscreentype(); /* Set up screentype structure */
- getlocale(); /* Sets up the preferred language */
- getfont(); /* Sets up the font structure */
- setupmainwindow(); /* Sets up the win1 NewWindow structure */
- changemenu(); /* Changes the menuitem structures to account font size */
-
- win_p = (struct Window *) OpenWindow ( &win1 );
- if(!win_p) {
- msg("Unable to open window!");
- closeall();
- return(0);
- }
- SetMenuStrip(win_p,&menu1);
-
- ispicture=loadpic(prefs.backdrop,pubscreen);
-
- /* Set up the timer.device */
-
- if(!(TimerPort=(struct MsgPort *)CreateMsgPort())) {
- msg("Unable to open timer msg port!");
- closeall();
- return(0);
- }
-
- TimerSig=1L<<TimerPort->mp_SigBit;
-
- if(!(TimerIO=(struct timerequest *)CreateIORequest(TimerPort,sizeof(struct timerequest)))) {
- msg("Problems with timer IO requests!!");
- closeall();
- return(0);
- }
-
- if(timerdev=OpenDevice("timer.device",UNIT_WAITUNTIL,(struct IORequest *)TimerIO,0)) {
- msg("Cannot open timer.device!");
- closeall();
- return(0);
- }
-
- TimerIO->tr_node.io_Command=TR_ADDREQUEST;
- TimerIO->tr_time.tv_micro=0;
-
- TimerBase=(struct Library *)TimerIO->tr_node.io_Device;
-
- GetSysTime(&TimerIO->tr_time);
- SendIO((struct IORequest *)TimerIO);
-
- /* End of timer bits */
-
- exit_flag=FALSE;
- winsig=1<<win_p->UserPort->mp_SigBit;
- totalsig=winsig|TimerSig;
-
- cxsucc=cxinit();
- rexxsucc=arexxinit();
-
- if(cxsucc) {
- cxsig=1<<CxMsgPort->mp_SigBit;
- hot1sig=1<<CxHotKey1->mp_SigBit;
- hot2sig=1<<CxHotKey2->mp_SigBit;
- totalsig=totalsig|hot1sig|hot2sig|cxsig;
- }
- if(rexxsucc) {
- rexxsig=1<<RexxPort->mp_SigBit;
- totalsig=totalsig|rexxsig;
- }
-
- while(exit_flag==FALSE) {
- sig=Wait(totalsig);
-
- if(sig==TimerSig) {
-
- gettime(); /* Set up the time structure */
-
- /* Make sure that at least one minute has passed before
- refreshing the window or if language changed. */
-
- flag1=FALSE;
-
- if(time.hours!=mem2) flag1=TRUE;
- if(time.minutes!=mem1) flag1=TRUE;
- if(!flag1) goto break_away;
- mem1=time.minutes; mem2=time.hours;
-
- refreshwindow();
- goto break_away;
- }
-
- if(sig==winsig) {
- while(message = (struct IntuiMessage *)GetMsg(win_p->UserPort)) {
- class=message->Class; code=message->Code;
- ReplyMsg((struct Message *)message);
-
-
- /* Now lets see what IDCMP message was sent: */
- switch (class) {
- case CLOSEWINDOW:
- exit_flag=TRUE;
- break;
- case NEWSIZE:
- refreshwindow();
- break;
- case MENUPICK:
- switch(ITEMNUM(code)) {
- case 0: /* Prefs */
- prefsgui();
- ClearMenuStrip(win_p);
- changemenu();
- SetMenuStrip(win_p,&menu1);
- ispicture=loadpic(prefs.backdrop,pubscreen);
- refreshwindow();
- break;
- case 1: /* Jump */
- jump();
- refreshwindow();
- break;
- case 2: /* About */
- about();
- break;
- case 3: /* Quit */
- exit_flag=TRUE;
- break;
- }
- break;
- } /* End of Switch */
- } /* End of while (GetMsg bit) */
- }
-
- if(sig==cxsig) {
- while(CxMessage=(CxMsg *)GetMsg(CxMsgPort)) {
- id=CxMsgID(CxMessage);
- ReplyMsg((struct Message *)CxMessage);
-
- switch(id) {
- case CXCMD_KILL:
- exit_flag=TRUE;
- break;
- case CXCMD_APPEAR:
- WindowToFront(win_p);
- prefsgui();
- ClearMenuStrip(win_p);
- changemenu();
- SetMenuStrip(win_p,&menu1);
- ispicture=loadpic(prefs.backdrop,pubscreen);
- refreshwindow();
- break;
- case CXCMD_DISABLE:
- // Wait for a CXCMD_ENABLE msg
- while(1) {
- WaitPort(CxMsgPort);
- CxMessage=(CxMsg *)GetMsg(CxMsgPort);
- id=CxMsgID(CxMessage);
- ReplyMsg((struct Message *)CxMessage);
- if(id==CXCMD_ENABLE) break;
- }
- default:
- break;
- }
- }
- }
-
- if(sig==hot1sig) {
- // Speak to me!
- CxMessage=(CxMsg *)GetMsg(CxHotKey1);
- if(CxMessage) ReplyMsg((struct Message *)CxMessage);
- strcpy(newline,line1);
- if(language==ENGLISH) newline[strlen(newline)-4]=NULL; /* Get rid of pm/am */
- strcat(newline,". ");
- if(prefs.date) {
- strcat(newline,line2);
- newline[strlen(newline)-6]=NULL; /* Get rid of year */
- }
- talk(trans(newline));
- }
-
- if(sig==hot2sig) {
- // Open window
- CxMessage=(CxMsg *)GetMsg(CxHotKey2);
- if(CxMessage) ReplyMsg((struct Message *)CxMessage);
- WindowToFront(win_p);
- prefsgui();
- ClearMenuStrip(win_p);
- changemenu();
- SetMenuStrip(win_p,&menu1);
- ispicture=loadpic(prefs.backdrop,pubscreen);
- refreshwindow();
- }
-
- if(sig==rexxsig)
- process_arexx();
-
-
- break_away:
- /* Reschedule the timer */
- GetSysTime(&TimerIO->tr_time);
- TimerIO->tr_time.tv_secs+=2;
- TimerIO->tr_time.tv_micro=0;
- SendIO((struct IORequest *)TimerIO);
- } /* End of while we havent quited bit */
-
- quitbit:
-
- closeall();
-
- return(0);
-
- } /* End of main() */
-
-
- void gettime(void) {
-
- /*****************************************/
- /* Gettime() function */
- /* ================== */
- /* */
- /* By Ben Matthew (C) 1995 */
- /* */
- /* Gettime() sets up the time structure */
- /* according to the time stamp on the */
- /* IntuiMessage IntuiTicks bit */
- /* */
- /*****************************************/
-
- ULONG seconds,micros;
- struct ClockData clock;
-
- CurrentTime(&seconds,µs);
- Amiga2Date(seconds,&clock); /* Utility.library function */
-
- time.seconds=clock.sec;
- time.hours=clock.hour;
- time.minutes=clock.min;
- time.months=clock.month;
- time.years=clock.year;
- time.days=clock.mday;
- time.wday=clock.wday;
- }
-
- short readprefs(void) {
- int bytes=0, i;
-
- handle=Open(PREFS_FILE,MODE_OLDFILE);
- if(!handle) {
- /* Preferences file NOT found, so set default settings... */
- prefs.x=0;prefs.y=0;prefs.width=370;prefs.height=32;
- prefs.planguage=1;
- for(i=0; i<8; i++) {
- prefs.date_col[i]=1;
- prefs.time_col[i]=1;
- }
- prefs.just=0;
- for(i=0; i<11; i++) {
- prefs.events[i].used=FALSE;
- prefs.events[i].type=0;
- prefs.events[i].hours=1;
- prefs.events[i].minutes=0;
- prefs.events[i].timecode=1;
- strcpy(prefs.events[i].message,"");
- prefs.events[i].day=1;
- prefs.events[i].month=1;
- prefs.events[i].year=1995;
- prefs.events[i].enabledate=FALSE;
- }
- prefs.date=FALSE;
- prefs.wtf=FALSE;
- prefs.autoadjust=FALSE;
- strcpy(prefs.backdrop,"");
- strcpy(prefs.pub,"");
- strcpy(prefs.accent,"locale:accents/english.accent");
- strcpy(prefs.hkey,"CONTROL ALT e");
- strcpy(prefs.tkey,"HELP");
- return(0);
- }
- /* If not returned by now, preferences file is open! */
-
- bytes=FRead(handle,(char *)&prefs,1,sizeof(prefs));
- if(bytes!=sizeof(prefs)) {
- /* Error reading prefs file */
- DisplayBeep(NULL);
- /* Set the default settings */
- prefs.x=0;prefs.y=0;prefs.width=370;prefs.height=32;
- prefs.planguage=1;
- for(i=0; i<8; i++) {
- prefs.date_col[i]=1;
- prefs.time_col[i]=1;
- }
- prefs.just=0;
- for(i=0; i<11; i++) {
- prefs.events[i].used=FALSE;
- prefs.events[i].type=0;
- prefs.events[i].hours=1;
- prefs.events[i].minutes=0;
- prefs.events[i].timecode=1;
- strcpy(prefs.events[i].message,"");
- prefs.events[i].day=1;
- prefs.events[i].month=1;
- prefs.events[i].year=1995;
- prefs.events[i].enabledate=FALSE;
- }
- prefs.date=FALSE;
- prefs.wtf=FALSE;
- prefs.autoadjust=FALSE;
- strcpy(prefs.backdrop,"");
- strcpy(prefs.pub,"");
- strcpy(prefs.accent,"locale:accents/english.accent");
- strcpy(prefs.hkey,"CONTROL ALT e");
- strcpy(prefs.tkey,"HELP");
- }
- if(strcmp(prefs.header,ID)) {
- DisplayBeep(NULL);
- msg("Error: Corrupt preferences header!");
- }
- Close(handle);
- return(0);
- }
-
- void setupengnums(void) {
- /********************************************************************/
- /* Set up Engnums */
- /* ============== */
- /* */
- /* This function sets up the engnums[] array with whatever */
- /* preferred language has been specified by language. This */
- /* function also sets up the line1 string which contains the */
- /* text which is displayed in the window. Being a nice modular */
- /* function this enables me to add in more supported languages */
- /* later! */
- /* */
- /********************************************************************/
-
- int temp1;
-
- if(time.hours>12) {
- time.hours=time.hours-12;
- afternoon=TRUE;
- }
- else {
- if(time.hours==12)
- afternoon=TRUE;
- else
- afternoon=FALSE;
- }
- if(time.hours==0) /* Midnight! */
- time.hours=12;
- switch(language) {
- case ENGLISH:
- strcpy(line1,"It's");
-
- engnums[1]="one"; engnums[2]="two";
- engnums[3]="three";
- engnums[4]="four"; engnums[5]="five"; engnums[6]="six";
- engnums[7]="seven"; engnums[8]="eight";
- engnums[9]="nine"; engnums[10]="ten";
- engnums[11]="eleven"; engnums[12]="twelve";
- engnums[13]="midnight"; engnums[14]="midday"; /* Special refs */
- engnums[15]="quarter"; engnums[20]="twenty";
- engnums[25]="twenty-five"; engnums[30]="half";
- engnums[35]="five and twenty"; engnums[40]="twenty";
- engnums[45]="quarter"; engnums[50]="ten";
- engnums[55]="five";
- temp1=(time.minutes/5)*5;
- if((time.minutes-temp1)<=2) {
- strcat(line1," just gone");
- }
- else {
- strcat(line1," nearly");
- }
- if(time.minutes>2 & time.minutes<58) {
- strcat(line1," ");
- if((time.minutes-temp1)<=2) {
- strcat(line1,engnums[(time.minutes/5)*5]);
- }
- else {
- strcat(line1,engnums[((time.minutes/5)+1)*5]);
- }
- }
- if(time.minutes>2 & time.minutes<58) {
- if(time.minutes<=32) {
- strcat(line1," past");
- }
- else {
- strcat(line1," to");
- }
- }
- strcat(line1," ");
- if(time.minutes<=32) {
- if(time.hours==12) {
- if(afternoon) {
- if(time.minutes>2) {
- strcat(line1,engnums[14]);
- }
- else {
- strcat(line1,engnums[12]);
- }
- }
- else {
- if(time.minutes>2) {
- strcat(line1,engnums[13]);
- }
- else {
- strcat(line1,engnums[12]);
- }
- }
- } else {
- strcat(line1,engnums[time.hours]);
- }
- } else {
- if(time.hours==12) {
- strcat(line1,engnums[1]);
- }
- else {
- if(time.hours==11) {
- if(afternoon) {
- if(time.minutes<58) {
- strcat(line1,engnums[13]);
- }
- else {
- strcat(line1,engnums[12]);
- }
- }
- else {
- if(time.minutes<58) {
- strcat(line1,engnums[14]);
- }
- else {
- strcat(line1,engnums[12]);
- }
- }
- }
- else {
- strcat(line1,engnums[time.hours+1]);
- }
- }
- }
- if((time.minutes<3) | (time.minutes>57) ) {
- strcat(line1," o'clock");
- }
-
- if(afternoon)
- strcat(line1," (pm)");
- else
- strcat(line1," (am)");
-
- if(time.hours!=12 & !(time.hours==11 & time.minutes>57) ) {
-
- break; /* End of english defines */
-
- case FRENCH:
- strcpy(line1,"Il est");
- engnums[1]="un"; engnums[2]="deux";
- engnums[3]="trois";
- engnums[4]="quatre"; engnums[5]="cinq"; engnums[6]="six";
- engnums[7]="sept"; engnums[8]="huit";
- engnums[9]="neuf"; engnums[10]="dix";
- engnums[11]="onze"; engnums[12]="douze";
- engnums[15]="et quart"; engnums[20]="vingt";
- engnums[25]="vingt-cinq"; engnums[30]="et demie";
- engnums[35]="vingt-cinq"; engnums[40]="vingt";
- engnums[45]="quart"; engnums[50]="dix";
- engnums[55]="cinq";
- temp1=(time.minutes/5)*5;
- if((time.minutes-temp1)>2)
- strcat(line1," bientôt");
- strcat(line1," ");
- if(time.minutes<=32) {
- strcat(line1,engnums[time.hours]);
- }
- else {
- if(time.hours==12) {
- strcat(line1,engnums[1]); }
- else {
- strcat(line1,engnums[time.hours+1]);
- }
- }
- strcat(line1," heures");
- if(time.minutes>2 & time.minutes<58) {
- strcat(line1," ");
- if(time.minutes>32)
- strcat(line1,"moins ");
- if((time.minutes-temp1)<=2) {
- strcat(line1,engnums[(time.minutes/5)*5]); }
- else {
- strcat(line1,engnums[((time.minutes/5)+1)*5]); }
- }
- if((time.minutes-temp1)<=2)
- strcat(line1," passées");
- break; /* End of french defines */
- case SPANISH:
- if((time.hours==1) || (time.hours==12 && time.minutes >= 33))
- strcpy(line1,"Es la ");
- /* Could add at this point aproximadamente, but +100 pixels */
- else
- strcpy(line1,"Son las ");
- engnums[1]="una"; engnums[2]="dos";
- engnums[3]="tres";
- engnums[4]="cuatro"; engnums[5]="cinco"; engnums[6]="seis";
- engnums[7]="siete"; engnums[8]="ocho";
- engnums[9]="nueve"; engnums[10]="diez";
- engnums[11]="once"; engnums[12]="doce";
- engnums[15]="cuarto"; engnums[20]="veinte";
- engnums[25]="veinticinco"; engnums[30]="media";
- engnums[35]="veinticinco"; engnums[40]="veinte";
- engnums[45]="cuarto"; engnums[50]="diez";
- engnums[55]="cinco";
- temp1=(time.minutes/5)*5;
- if(time.minutes<=32)
- strcat(line1,engnums[time.hours]);
- else {
- if(time.hours==12)
- strcat(line1,engnums[1]);
- else
- strcat(line1,engnums[time.hours+1]);
- }
- if(time.minutes>2 & time.minutes<58) {
- if(time.minutes<=32)
- strcat(line1," y");
- else
- strcat(line1," menos");
- strcat(line1," ");
- if((time.minutes-temp1)<=2) {
- strcat(line1,engnums[(time.minutes/5)*5]); }
- else {
- strcat(line1,engnums[((time.minutes/5)+1)*5]); }
- }
- strcat(line1," ");
-
- if(!afternoon) {
- /* Morning (AM) */
- if( (time.hours==12 && time.minutes >= 33) ||
- (time.hours==4 && time.minutes <= 32) ||
- (time.hours >= 1 && time.hours <= 3)
- ) strcat(line1,"de la magruda");
-
- if( (time.hours==4 && time.minutes >=33) ||
- (time.hours==11 && time.minutes <= 32) ||
- (time.hours >= 5 && time.minutes <= 10)
- ) strcat(line1,"de la mañana");
-
- if(time.hours==11 && time.minutes >=33) strcat(line1,"del mediodia");
-
- } else {
- /* Afternoon/Evening (PM) */
-
- if(time.hours==12 && time.minutes <=32) strcat(line1,"de la noche");
-
- if( (time.hours==12 && time.minutes >=33) ||
- (time.hours==8 && time.minutes <= 32) ||
- (time.hours >= 1 && time.hours <= 7)
- ) strcat(line1,"de la tarde");
-
- if( (time.hours==8 && time.minutes >=33) ||
- (time.hours==11 && time.minutes <= 32) ||
- (time.hours >= 9 && time.hours <= 10)
- ) strcat(line1,"de la noche");
-
- if( (time.hours==11 && time.minutes >=33) ||
- (time.hours==12 && time.minutes <=32)
- ) strcat(line1,"del mediodia");
- }
-
- break; /* End of spanish defines */
- }
-
- } /* end of switch */
- } /* end of function */
-
- void getfont(void) {
-
- /***************************************************/
- /* Get Font Dimensions */
- /* =================== */
- /* */
- /* This routine finds out what the default font is */
- /* and sets up the structure "font" with the */
- /* dimensions of the default font */
- /* */
- /***************************************************/
-
- font.x=GfxBase->DefaultFont->tf_XSize;
- font.y=GfxBase->DefaultFont->tf_YSize;
-
- }
-
- void openall(void) {
-
- /**********************************************************/
- /* Open all libraries and devices */
- /* ============================== */
- /* */
- /* A very simple routine that opens all the libraries */
- /* and devices needed by the program. All the */
- /* open library/device reqeusts are tested individually */
- /* since it helps if I know what library/device didn't */
- /* open when testing */
- /**********************************************************/
-
- /* Some functions used in this program are illegal under KS1.3 so
- just do a quick check to make sure we are running OS 2.x+ */
-
- /* if(SysBase->LibNode.lib_Version<37) {
- msg("EngClock requires OS 2.0 or higher to run!");
- closeall();
- exit(NULL);
- } */
-
- // Set up global bases
-
- IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0);
- GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0);
- DiskfontBase=OpenLibrary("diskfont.library",0);
- GadToolsBase=OpenLibrary("gadtools.library",0);
- UtilityBase=OpenLibrary("utility.library",0);
- CxBase=OpenLibrary("commodities.library",0);
-
- if(!(IntuitionBase && GfxBase && DiskfontBase && GadToolsBase && UtilityBase)) {
- msg("Unable to open needed libs!");
- closeall();
- exit(NULL);
- }
-
- /* This just wakes up narrator device if available */
- talk(" ");
- }
-
- void closeall(void) {
-
- /************************************************************/
- /* Close all libraries and devices */
- /* =============================== */
- /* */
- /* This simple routine is the opposite to openall(). It */
- /* closes any libraries/devices that have been opened by */
- /* the program. Each library is tested before closing. */
- /************************************************************/
-
- int retry=0;
-
- if(ispicture) unloadpic(piccy);
-
- if(pubscreen) UnlockPubScreen(NULL,pubscreen);
-
- if(win_p) {
- ClearMenuStrip(win_p);
- CloseWindow(win_p);
- }
- if(!timerdev) CloseDevice((struct IORequest *)TimerIO);
- if(TimerIO) DeleteIORequest(TimerIO);
-
- if(TimerPort)
- DeleteMsgPort(TimerPort);
-
- if(cxsucc) cxclose();
- if(rexxsucc) arexxclose();
-
- if(UtilityBase) CloseLibrary(UtilityBase);
- if(GfxBase) CloseLibrary((struct Library *)GfxBase);
- if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
- if(GadToolsBase) CloseLibrary(GadToolsBase);
- if(DiskfontBase) CloseLibrary(DiskfontBase);
- if(CxBase) CloseLibrary(CxBase);
-
- }
-
- void clearwindow(void) {
-
- /*********************************************/
- /* Clear Window */
- /* ============ */
- /* */
- /* A very simple routine to clear the main */
- /* window of everything its got! Part of */
- /* English Clock's refresh routine. New */
- /* V2.5 feature is that it is now properly */
- /* font sensitive!! */
- /*********************************************/
-
- int x,y,width,height;
-
- y=screentype.s_bar+2; /* Allow 2 more pixels to be safe */
- x=6; /* Allow room for the fixed width left window line */
- width=win_p->Width-20; /* Allow room for the bigger right line */
- height=win_p->Height-3; /* Allow room for the thin bottom line */
-
- if(ispicture) {
- pattern(win_p,pubscreen,piccy);
- }
- else {
- SetAPen(win_p->RPort,0);
- RectFill(win_p->RPort,x,y,width,height);
- SetAPen(win_p->RPort,1);
- }
-
- }
-
- short setupmainwindow(void) {
-
- /**************************************************/
- /* Set up main window */
- /* ================== */
- /* */
- /* This routine makes the main window assignment */
- /* Note that no globally braced assignment is */
- /* defined previous since for some reason if you */
- /* touch a NewWindow struct after globally */
- /* assigning it then all hell breaks loose! */
- /**************************************************/
-
- /* Note to coders: Okay I know that there is probably a much easier and
- nicer way to do this then below but who cares?!!? It works dunnit? */
-
- BOOL screenflag=FALSE;
-
- /* Stuff at beginning (LeftEdge...) assigned below */
-
- win1.DetailPen=0;
- win1.BlockPen=1;
- win1.IDCMPFlags=CLOSEWINDOW|MENUPICK|NEWSIZE;
- win1.Flags=SMART_REFRESH|WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH|WINDOWSIZING|ACTIVATE;
- win1.FirstGadget=NULL;
- win1.CheckMark=NULL;
- win1.Title="English Clock 7.0 © 1996 by Ben Matthew";
- if(language==SPANISH)
- win1.Title="English Clock 7.0 © 1996 por Ben Matthew";
- win1.Screen=pubscreen;
- win1.BitMap=NULL;
- win1.MaxWidth=640;
- win1.MaxHeight=256; /* This should be enough for any font size! */
- win1.Type=CUSTOMSCREEN;
-
- /* First change the window dimensions to the ones specified by prefs */
-
- win1.LeftEdge=prefs.x;
- win1.TopEdge=prefs.y;
- win1.Width=prefs.width;
- win1.Height=prefs.height;
-
- /* The next bit is a wee bit more complex since it has to take into
- account the font size and what not */
-
- /* The maximum length that the time can be is:
-
- English = 47 total characters */
-
- /* The minimum is 23 chars */
-
- /* Hokay, I have had a brainwave!! Why dont we be nice and allow users
- who have huge res workbenches to enlarge their windows even more!! */
-
- win1.MaxWidth=screentype.s_width;
- win1.MaxHeight=screentype.s_height;
-
- if(prefs.autoadjust) {
- win1.MinHeight=screentype.s_bar+font.y+5;
- win1.MinWidth=40;
- return(1);
- }
-
- win1.MinWidth=(47*font.x)+40; /* Leave 40 to be sure */
-
- if(prefs.date)
- win1.MinHeight=(font.y*2)+screentype.s_bar+16;
- else
- win1.MinHeight=font.y+screentype.s_bar+16;
-
-
- /* Now if a particularly font is used and the above calculation creates
- Minimum values larger than can be displayed on the current screen then
- EngClock refuses to open and doesn't close the libs proper - not very
- nice!! So do a quick check!! */
-
-
- if(win1.MinWidth > screentype.s_width)
- screenflag=TRUE;
- if(win1.MinHeight > screentype.s_height)
- screenflag=TRUE;
- if(screenflag) {
- msg("Sorry but your screen dimension is too small for EngClock to use with your current font size!");
- closeall();
- exit(NULL);
- }
-
- /* Do a quick check to make sure that the current width and height do not
- exceed the max (+vv). This should NEVER happen but it could if someone
- or something tampers with the preferences file! */
-
-
- if(win1.Width > win1.MaxWidth) win1.Width=win1.MaxWidth;
- if(win1.Height > win1.MaxHeight) win1.Height=win1.MaxHeight;
-
- if(win1.Width < win1.MinWidth) win1.Width=win1.MinWidth;
- if(win1.Height < win1.MinHeight) win1.Height=win1.MinHeight;
-
- /* Now check if the window is in the right place */
-
- while (win1.LeftEdge+win1.Width > screentype.s_width) {
- win1.LeftEdge--;
- if (win1.LeftEdge== -1) {
- msg("Window too big for screen!");
- closeall();
- exit(NULL);
- }
- }
-
- while (win1.TopEdge+win1.Height > screentype.s_height) {
- win1.TopEdge--;
- if (win1.TopEdge== -1) {
- msg("Window too big for screen!");
- closeall();
- exit(NULL);
- }
- }
-
- /* Right then, all done. Return and let main() do its stuff!! */
-
- return(0);
-
- }
-
- short changemenu(void) {
-
- /* Function changes the Height elements of the MenuItems so that it
- takes into account font sizes */
-
- int height;
- height = screentype.s_bar; /* Allow a bit of space top and bot */
-
- switch(language) {
- case ENGLISH:
- menu1.MenuName="Project";
- menu_text1.IText="Set Prefs...";
- menu_text2.IText="Jump";
- menu_text3.IText="About...";
- menu_text4.IText="Quit";
- menu_item1.Command='S';
- menu_item2.Command='J';
- menu_item3.Command='A';
- menu_item4.Command='Q';
- break;
- case FRENCH:
- menu1.MenuName="Projet";
- menu_text3.IText="Autour";
- menu_text2.IText="Sauter";
- menu_text4.IText="Quitte";
- menu_text1.IText="Ensemble...";
- menu_item1.Command='E';
- menu_item2.Command='S';
- menu_item3.Command='A';
- menu_item4.Command='Q';
- break;
- case SPANISH:
- menu1.MenuName="Proyecto";
- menu_text3.IText="Sobre...";
- menu_text2.IText="Ir a pantalla";
- menu_text4.IText="Salir";
- menu_text1.IText="Prefs...";
- menu_item1.Command='P';
- menu_item2.Command='I';
- menu_item3.Command='?';
- menu_item4.Command='S';
- break;
-
- default:
- msg("Internal error (language !=1,2,3)");
- break;
- }
- menu_item1.Height=height; /* First item in first menu */
- menu_item2.Height=height; menu_item2.TopEdge=height;
- menu_item3.Height=height; menu_item3.TopEdge=(height*2);
- menu_item4.Height=height; menu_item4.TopEdge=(height*3);
-
- /* Menu 1 = Project (7), Menu 2 = Preferences (11) */
-
- /* Note that I am being forced to make the assumption that the font
- being used for the windows has the same width and height dimensions
- although this is highly unlikely I cannot find a way to locate this
- other measurement */
-
-
- menu1.Width=(7*(screentype.s_bar-2))+5;
-
- /* Changes widths to be font sensitive + allow hotkey spacing */
-
- menu_item1.Width=(19*(screentype.s_bar-2))+COMMWIDTH;
- menu_item2.Width=(19*(screentype.s_bar-2))+COMMWIDTH;
- menu_item3.Width=(19*(screentype.s_bar-2))+COMMWIDTH;
- menu_item4.Width=(19*(screentype.s_bar-2))+COMMWIDTH;
-
- if((19*(screentype.s_bar-2))+COMMWIDTH > screentype.s_width) {
- msg("Font size is too big to create menus!!");
- closeall();
- exit(NULL);
- }
-
- return(0);
-
- }
-
- short refreshwindow(void) {
- /* Simple routine which calls funcs that together redraw the main
- window. Placed in its own function as of version 2.6 so that I
- can redraw the window's contents any time I want, esp. with NEWSIZE */
-
- int length, space_avail;
-
- setupengnums();
- if(language==1) setupdate_english();
- if(language==2) setupdate_french();
- if(language==3) setupdate_spanish();
-
-
- if(prefs.wtf)
- WindowToFront(win_p);
-
- int_text.IText=line1;
- date_text.IText=line2;
-
- if(prefs.autoadjust)
- autoadjust();
- else {
- // Make sure that the MinWidths are not set for autoadjust
- if(win_p->MinWidth != (47*font.x)+40) {
- // N.B Not checking MinHeight due to complicated routine
- // Update win1
- win1.LeftEdge=win_p->LeftEdge;
- win1.TopEdge=win_p->TopEdge;
- win1.Height=win_p->Height;
- win1.Width=win_p->Width;
-
- win1.MinWidth=(47*font.x)+40;
- if(prefs.date)
- win1.MinHeight=(font.y*2)+screentype.s_bar+16;
- else
- win1.MinHeight=font.y+screentype.s_bar+16;
-
- ClearMenuStrip(win_p);
- CloseWindow(win_p);
-
- if(!(win_p=OpenWindow(&win1))) {
- // There is no reason why this should fail since we updated
- msg("Error re-opening window (system failure!!)");
- closeall();
- exit(NULL);
- }
- SetMenuStrip(win_p,&menu1);
- }
- }
- switch(prefs.just) {
- case 0: /* Left */
- int_text.LeftEdge=16;
- date_text.LeftEdge=16;
- break;
- case 1: /* Centre */
- length=strlen(line1)*font.x;
- space_avail=win_p->Width-26;
- int_text.LeftEdge=(space_avail-length)/2;
- length=strlen(line2)*font.x;
- date_text.LeftEdge=(space_avail-length)/2;
- break;
- case 2: /* Right */
- length=strlen(line1)*font.x;
- space_avail=win_p->Width-26;
- int_text.LeftEdge=space_avail-length;
- length=strlen(line2)*font.x;
- date_text.LeftEdge=space_avail-length;
- break;
- }
-
-
-
-
- clearwindow();
- if(prefs.date) {
- if(((win_p->MinHeight < (screentype.s_bar+(font.y*2)+16)) &&!(prefs.autoadjust)) || (prefs.autoadjust && (win_p->Height < (screentype.s_bar+(font.y*2)+16))) ) {
- /* Update the win1 structure to accomodate the new win_p dimensions */
- win1.TopEdge=win_p->TopEdge;
- win1.LeftEdge=win_p->LeftEdge;
- win1.Width=win_p->Width;
- win1.Height=win_p->Height;
- ClearMenuStrip(win_p);
- CloseWindow(win_p);
- if(!prefs.autoadjust)
- win1.MinHeight=screentype.s_bar+(font.y*2)+16;
- win1.Height=screentype.s_bar+(font.y*2)+16;
- while ((win1.TopEdge+win1.Height) > screentype.s_height) {
- win1.TopEdge--;
- if(win1.TopEdge < 0) {
- DisplayBeep(NULL);
- closeall();
- exit(NULL);
- }
- }
- win_p=OpenWindow(&win1);
- SetMenuStrip(win_p,&menu1);
- if(!win_p) {
- DisplayBeep(NULL);
- closeall();
- exit(NULL);
- }
- SetMenuStrip(win_p,&menu1);
- }
- date_text.TopEdge=(((win_p->Height-((2*font.y)+(screentype.s_bar-6)))/2)+font.y);
- int_text.TopEdge=((win_p->Height-((2*font.y)+(screentype.s_bar-6)))/2)-2;
-
- date_text.FrontPen=prefs.date_col[screentype.s_mode];
- PrintIText(win_p->RPort,&date_text,0,screentype.s_bar-2);
- } else {
- /* Only one line needed */
- if(win_p->MinHeight > (screentype.s_bar+16+font.y)) {
- ClearMenuStrip(win_p);
- CloseWindow(win_p);
- win1.MinHeight=screentype.s_bar+16+font.y;
- win1.Height=screentype.s_bar+16+font.y;
- win_p=OpenWindow(&win1);
- if(!win_p) {
- DisplayBeep(NULL);
- closeall();
- exit(NULL);
- }
- SetMenuStrip(win_p,&menu1);
- }
- int_text.TopEdge=((win_p->Height-font.y-screentype.s_bar)/2)+2;
- }
- int_text.FrontPen=prefs.time_col[screentype.s_mode];
-
- PrintIText(win_p->RPort,&int_text,0,screentype.s_bar-2);
- process_alarm();
-
- return(0);
- }
-
- void setupdate_english(void) {
- char tmp[10];
-
- strcpy(line2,days_data[time.wday]);
-
- switch(time.days) {
- case 1:
- /* First day */
- strcat(line2," 1st ");
- break;
- case 2:
- strcat(line2," 2nd ");
- break;
- case 3:
- strcat(line2," 3rd ");
- break;
- case 21:
- strcat(line2," 21st ");
- break;
- case 22:
- strcat(line2," 22nd ");
- break;
- case 23:
- strcat(line2," 23rd ");
- break;
- case 30:
- strcat(line2," 30th ");
- break;
- case 31:
- strcat(line2," 31st ");
- break;
- default:
- sprintf(tmp," %ld",time.days);
- strcat(line2,tmp);
- strcat(line2,"th ");
- break;
- } /* End of switch(time.days) */
- strcat(line2,months_data[time.months]);
- strcat(line2,", ");
- sprintf(tmp,"%ld",time.years);
- strcat(line2,tmp);
- } /* End of ENGLISH */
-
-
- void setupdate_spanish(void) {
- char tmp[10];
- strcpy(line2,days_data_spanish[time.wday]);
- strcat(line2,",");
- sprintf(tmp," %ld ",time.days);
- strcat(line2,tmp);
- strcat(line2,"de ");
- strcat(line2,months_data_spanish[time.months]);
- strcat(line2," de");
- sprintf(tmp," %ld",time.years);
- strcat(line2,tmp);
-
- }
-
- void setupdate_french(void) {
- char tmp[10];
-
- strcpy(line2,days_data_french[time.wday]);
- sprintf(tmp," %ld ",time.days);
- strcat(line2,tmp);
- strcat(line2,months_data_french[time.months]);
- sprintf(tmp,", %ld",time.years);
- strcat(line2,tmp);
- } /* End of French */
-
-